package com.geekchique.runningbuddy.activity;

import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.Menu.Item;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.controller.DayOfJogDetailsControllerImpl;
import com.geekchique.runningbuddy.controller.IDayOfJogDetailsController;
import com.geekchique.runningbuddy.controller.IOptionsMenu;
import com.geekchique.runningbuddy.controller.OptionsMenuImpl;
import com.geekchique.runningbuddy.model.Jog;
import com.geekchique.runningbuddy.provider.ActivityID;
import com.geekchique.runningbuddy.view.dayofjogdetails.DayOfJogDetailsListAdapter;

public class DayOfJogDetails extends ListActivity{
	
	private IDayOfJogDetailsController dayOfJogDetailsController;
	private IOptionsMenu optionsMenu;
	
	@Override
	protected void onCreate(Bundle icicle) {
			super.onCreate(icicle);
			setContentView(R.layout.day_of_jogs);
			dayOfJogDetailsController = new DayOfJogDetailsControllerImpl(this);
			optionsMenu = new OptionsMenuImpl(this);
		 
		  	Bundle bundle = this.getIntent().getExtras();
	        Integer dayOfMonth = bundle.getInt(ActivityID.DAY_OF_MONTH); 
	        Integer monthOfYear = bundle.getInt(ActivityID.MONTH_OF_YEAR); 
	        Integer year = bundle.getInt(ActivityID.YEAR); 
	        
	        
	        TextView miles = new TextView(this);
	        miles.setText("miles Run");
			TextView name = new TextView(this);
			name.setText("name of jog");
			TextView timerun = new TextView(this);
			timerun.setText("time");
	        
	        dayOfJogDetailsController.createLastJogEntryView( this, miles, name, timerun);
	        
//	        dayOfJogDetailsController.populateTodaysJoggingTotals();
	        
	        populateTodaysJoggingEntries(dayOfJogDetailsController.getDayOfJogs(dayOfMonth, monthOfYear, year));
	    }

	private void populateTodaysJoggingEntries(List<Jog> jogEntries) {
		
		if (jogEntries.size() > 0){
			displayAllJogsTodayDetails(jogEntries);
		}
		
	}

	private void displayAllJogsTodayDetails(List<Jog> jogEntries) {
//		long longOfTimeRun = entry.getStopTime() - entry.getStartTime();
		
        ListAdapter adapter = new DayOfJogDetailsListAdapter(this, jogEntries);
		
        setListAdapter(adapter);
	
	}
	
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		optionsMenu.selectItem(item);
	    return super.onOptionsItemSelected(item);
	}
}
